home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / sbin / MAKEFLOPPIES < prev    next >
Encoding:
Text File  |  2007-03-05  |  5.1 KB  |  262 lines

  1. #!/bin/sh
  2. #
  3. # MAKEFLOPPIES
  4. #
  5. # requires: expr
  6. # Note quirk of expr: if it prints "0", it always
  7. # returns "1" regardless of whether this makes sense!
  8. #
  9. # 1995.01.03    David Niemi    Created
  10.  
  11. set -e
  12. set -u
  13.  
  14. # check for devfs
  15. if [ -e /dev/.devfsd ]; then
  16.     echo "devfs found, skipping MAKEFLOPPIES..." >&2
  17.     exit 0
  18. fi
  19.  
  20. MAJOR=2
  21. TMPDEVICE=/dev/tmpfloppy$$
  22. if [ ! -b /dev/fd0 ] ; then
  23.     mknod /dev/fd0 b $MAJOR 0
  24. fi
  25. if floppycontrol 2>/dev/null; then
  26.     FLOPPYCONTROL=yes
  27. else
  28.     FLOPPYCONTROL=no
  29. fi
  30.  
  31. MINORNAMES='d360 h1200 D360 D720 h360 h720 H1440 E2880
  32.     CompaQ h1440 H1680 h410 H820 h1476 H1722 h420
  33.     H830 h1494 H1743 h880 D1040 D1120 h1600 H1760
  34.     H1920 E3200 E3520 E3840 H1840 D800 H1600'
  35.  
  36. CMOSNAMES='360K_PC 1.2M_AT 720K 1.44M 2.88M_AMI_BIOS 2.88M'
  37.  
  38. ## Used only with -t option
  39. CMOSLETTERS='d h D H E E'
  40. UCMOSLETTERS='d h u u u u'
  41. CMOSFORMATS='d h D DH DHE DHE'
  42.  
  43. LOCAL=
  44. DRIVES=
  45. USAGE=
  46. TYPE_OVERRIDE=u
  47. REMAINDER=
  48. DRYRUN=
  49. VERBOSE=
  50.  
  51.  
  52. ## getword nth parameter of all the subsequent parameters
  53. getword ()
  54. {    if [ $# -lt 1 ]; then
  55.         return
  56.     fi
  57.     if [ "$1" -lt 1 ] || [ "$1" -ge $# ]; then
  58.         return
  59.     fi
  60.     shift $1
  61.     echo $1
  62. }
  63.  
  64. basenumber()
  65. {
  66.     if [ $1 -ge 4 ] ; then
  67.         expr $1 + 124
  68.     else
  69.         echo $1
  70.     fi
  71. }
  72.  
  73. minorname ()
  74. {    if [ "$FLOPPYCONTROL" = no ]; then
  75.         ## No floppycontrol program, so use default values
  76.         getword "$1" $MINORNAMES
  77.     else
  78.         rm -f "$TMPDEVICE"
  79.         mknod "$TMPDEVICE" b "$MAJOR" "$1"
  80.         floppycontrol -T "$TMPDEVICE" 2>/dev/null || :
  81.         rm -f "$TMPDEVICE"
  82.     fi
  83.  
  84. }
  85.  
  86. cmosid ()
  87. {
  88.     if [ "$FLOPPYCONTROL" = yes ]; then
  89.         case `minorname $1` in
  90.         d360)        echo 1 ;;
  91.         h1200)        echo 2 ;;
  92.         D720)        echo 3 ;;
  93.         H1440)        echo 4 ;;
  94.         E2880)        echo 6 ;;
  95.         "(null)")    echo none ;;
  96.         "")        echo none ;;
  97.         *)        echo unknown ;;
  98.         esac
  99.     elif [ "$1" = 0 ]; then
  100.         echo 4        # 1.44MB default for drive 0
  101.     elif [ "$1" = 1 ]; then
  102.         echo 2        # 1.2MB AT default for drive 1
  103.     else
  104.         echo none    # Nothing for everybody else
  105.     fi
  106. }
  107.  
  108. # main()
  109.  
  110. PERMISSION=666
  111. while [ $# -ge 1 ] || [ -n "${REMAINDER}" ]; do
  112.     if [ -n "$REMAINDER" ]; then
  113.         ## Continue processing options stuck together
  114.         ARG=$REMAINDER
  115.     else
  116.         ## Get a fresh argument
  117.         ARG=$1
  118.         shift
  119.         case "$ARG" in
  120.  
  121.         ## Remove dash in front of option(s)
  122.         -?*)
  123.             ARG=`expr "-$ARG" : '-*\(.*\)' || :`
  124.             ;;
  125.         esac
  126.     fi
  127.  
  128.     ## Break compound options up
  129.     case "$ARG" in
  130.     ??*)    REMAINDER=`expr "$ARG" : '.\(.*\)' || :`
  131.         ARG=`expr "$ARG" : '\(.\)' || :`
  132.         ;;
  133.     *)    REMAINDER= ;;
  134.     esac
  135.  
  136.     case $ARG in
  137.  
  138.     ## Process drive number(s)
  139.     [0-7])    DRIVES="$DRIVES $ARG" ;;
  140.  
  141.     [nN])    DRYRUN=yes ;;
  142.  
  143.     ## Make devices in current directory, not /dev
  144.     [lL])    LOCAL=yes ;;
  145.  
  146.     ## Base device name on drive type
  147.     [tT])    TYPE_OVERRIDE=yes ;;
  148.     [dD])    TYPE_OVERRIDE=yes ;;
  149.  
  150.     ## Base device name on media type
  151.     [mM])    TYPE_OVERRIDE=no ;;
  152.  
  153.     ## New naming scheme
  154.     [uU])    TYPE_OVERRIDE=no ;;
  155.  
  156.     [vV])    VERBOSE=yes ;;
  157.  
  158.     ## Allow access only for group floppy
  159.     [gG])    PERMISSION=660 ;;
  160.  
  161.     *)    echo "$0: unrecognized argument \"$ARG\"." >&2
  162.         USAGE=yes
  163.         ;;
  164.     esac
  165. done
  166.  
  167. if [ -n "$USAGE" ]; then
  168.     echo "Usage: $0 [ <option> ... ] [ <drive #> ... ]" >&2
  169.     echo 'Options:
  170.     -l    Local (make files in local directory, not /dev)
  171.     -n    Dry run (just report what would be done, do not do anything)
  172.     -t    Name devices for drive type
  173.     -d    Name devices for drive type
  174.     -m    Name devices for media type
  175.     -u    Use the same letter (u) for all 3 1/2 devices
  176.     -g    Allow access only for group floppy
  177.     -v    Verbose
  178. ' >&2
  179.     exit 1
  180. fi
  181.  
  182. if [ -z "$DRIVES" ]; then
  183.     DRIVES="0 1 2 3 4 5 6 7"
  184. fi
  185.  
  186. for DRIVE in $DRIVES; do
  187.     if [ -n "$LOCAL" ]; then
  188.         FILE=fd$DRIVE
  189.     else
  190.         FILE=/dev/fd$DRIVE
  191.     fi
  192.     BASENUMBER=`basenumber $DRIVE`
  193.     CMOS=`cmosid "$BASENUMBER"`
  194.     if [ $CMOS = none ] ; then
  195.         echo "Drive $DRIVE is not installed or not configured, skipping"
  196.         continue
  197.     fi
  198.  
  199.     if [ $CMOS = unknown ] ; then
  200.         echo "Drive $DRIVE is of unknown type, skipping"
  201.         continue
  202.     fi    
  203.  
  204.     CN=`getword "$CMOS" $CMOSNAMES`
  205.  
  206.     if [ "$TYPE_OVERRIDE" = u ]; then
  207.         CL=`getword "$CMOS" $UCMOSLETTERS`
  208.     else
  209.         CL=`getword "$CMOS" $CMOSLETTERS`
  210.     fi
  211.  
  212.     FORMATS=`getword "$CMOS" $CMOSFORMATS`
  213.     if [ -n "$VERBOSE" ] || [ -n "$DRYRUN" ]; then
  214.         echo rm -f "$FILE"*
  215.     fi
  216.     if [ -z "$DRYRUN" ]; then
  217.         rm -f "$FILE"*
  218.     fi
  219.     if [ -z "$CMOS" ] || [ -z "$CN" ]; then
  220.         echo "Skipping invalid drive \"$FILE\"" >&2
  221.         continue
  222.     fi
  223.     echo "Creating \"$FILE\", ID=$DRIVE, Type=$CMOS ($CN)"
  224.     if [ -z "$DRYRUN" ]; then
  225.         mknod "$FILE" b "$MAJOR" "$BASENUMBER"
  226.         chown root:floppy "$FILE"
  227.         chmod ${PERMISSION} "$FILE"
  228.     fi
  229.     if [ -n "$VERBOSE" ] || [ -n "$DRYRUN" ]; then
  230.         echo mknod "$FILE" b "$MAJOR" "$BASENUMBER"
  231.     fi
  232.  
  233.     ## Todo: query about tracks and such (for now assume 80 only)
  234.  
  235.     BASE=4
  236.     while [ $BASE -lt 128 ] ; do
  237.         MINOR=`expr "$BASE" + "$BASENUMBER" || :`
  238.         NAME=`minorname "$BASE"`
  239.         if expr index "$FORMATS" "$NAME" >/dev/null ; then
  240.             if [ "$TYPE_OVERRIDE" != no ]; then
  241.                 NAME=`echo $NAME | sed "s/^./$CL/g"`
  242.             fi
  243.         
  244.             if [ -z    "$NAME" ]; then
  245.                 echo "Oops, skipping invalid format \"$FORMAT\"" >&2
  246.                 continue
  247.             fi
  248.             if [ -z "$DRYRUN" ]; then
  249.                 mknod "${FILE}${NAME}" b "$MAJOR" "$MINOR"
  250.                 chown root:floppy "${FILE}${NAME}"
  251.                 chmod ${PERMISSION} "${FILE}${NAME}"
  252.             fi
  253.             if [ -n "$VERBOSE" ] || [ -n "$DRYRUN" ]; then
  254.                 echo mknod "${FILE}${NAME}" b "$MAJOR" "$MINOR"
  255.             fi
  256.         fi
  257.         BASE=`expr $BASE + 4`
  258.     done
  259. done
  260.  
  261. ## END ##
  262.